package edu.hawaii.myisern.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Encapsulates the researcher record.
 * 
 * @author Randy Cox
 * 
 */
public class MyCollaboration {

  private Id id;
  private String name;
  private String description;
  private List<String> organizations;
  private List<String> years;
  private List<String> types;
  private List<String> outcomes;

  /**
   * Initialize the data.
   */
  public MyCollaboration() {
    initialize();
  }

  /**
   * Initialize and clear record.
   */
  public final void initialize() {
    this.id = new Id();
    this.name = "";
    this.description = "";
    this.organizations = new ArrayList<String>();
    this.years = new ArrayList<String>();
    this.types = new ArrayList<String>();
    this.outcomes = new ArrayList<String>();
  }

  /**
   * @return the id
   */
  public String getId() {
    return id.toString();
  }

  /**
   * Gets name.
   * 
   * @return the name
   */
  public String getName() {
    return name;
  }

  /**
   * Sets name.
   * 
   * @param name the name to set
   */
  public void setName(String name) {
    this.id = new Id(name);
    this.name = name;
  }

  /**
   * Gets description.
   * 
   * @return the description
   */
  public String getDescription() {
    return description;
  }

  /**
   * Sets description.
   * 
   * @param description the description to set
   */
  public void setDescription(String description) {
    this.description = description;
  }

  /**
   * Returns a copy of the organization list.
   * 
   * @return the organizations
   */
  public List<String> getOrganizations() {
    List<String> list = new ArrayList<String>();
    list.addAll(this.organizations);
    return list;
  }

  /**
   * Set organizations.
   * 
   * @param organizations the organizations to set
   */
  public void setOrganizations(List<String> organizations) {
    List<String> list = new ArrayList<String>();
    list.addAll(organizations);
    this.organizations = list;
  }

  /**
   * Add organization to list.
   * 
   * @param organization to add
   */
  public void addOrganization(String organization) {
    this.organizations.add(organization);
  }

  /**
   * Get years.
   * 
   * @return the years
   */
  public List<String> getYears() {
    List<String> list = new ArrayList<String>();
    list.addAll(this.years);
    return list;
  }

  /**
   * Set years.
   * 
   * @param years the years to set
   */
  public void setYears(List<String> years) {
    List<String> list = new ArrayList<String>();
    list.addAll(years);
    this.years = list;
  }

  /**
   * Add on year to list.
   * 
   * @param year to add
   */
  public void addYear(String year) {
    this.years.add(year);
  }

  /**
   * Get types.
   * 
   * @return the types
   */
  public List<String> getTypes() {
    List<String> list = new ArrayList<String>();
    list.addAll(this.types);
    return list;
  }

  /**
   * Set types.
   * 
   * @param types the types to set
   */
  public void setTypes(List<String> types) {
    List<String> list = new ArrayList<String>();
    list.addAll(types);
    this.types = list;
  }

  /**
   * Add on type to list.
   * 
   * @param type the type to add
   */
  public void addType(String type) {
    this.types.add(type);
  }

  /**
   * Get outcomes.
   * 
   * @return the outcomes
   */
  public List<String> getOutcomes() {
    List<String> list = new ArrayList<String>();
    list.addAll(this.outcomes);
    return list;
  }

  /**
   * Set outcomes.
   * 
   * @param outcomes the outcomes to set
   */
  public void setOutcomes(List<String> outcomes) {
    List<String> list = new ArrayList<String>();
    list.addAll(outcomes);
    this.outcomes = list;
  }

  /**
   * Add on outcome to list.
   * 
   * @param outcome the outcome to add
   */
  public void addOutcome(String outcome) {
    this.outcomes.add(outcome);
  }

  /**
   * Checks if record has id, name and email populated.
   * 
   * @return true if required fields are populated.
   */
  public Boolean validate() {
    Boolean ok = ((this.id != null) && (this.name != null) && (this.description != null)
        && (this.organizations != null) && (this.types != null) 
        && (this.years != null) && (this.outcomes != null));
    if (ok) {
      ok = ((!this.id.toString().isEmpty()) && (!this.name.isEmpty()));
    }
    return ok;
  }

  /**
   * Creates a string delimited by commas of the record contents.
   * 
   * @return string of record data.
   */
  public String toString() {
    String string = "";
    if (this.validate()) {
      String comma = ", ";
      string = getId() + comma + getName() + comma + getDescription();
    }
    return string;
  }
}
